{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 官方文档提供了本书之外的大量描述和示例\n",
    "* 可以调用$dir$和$help$函数或在jupyter中使用$?$和$??$来查看文档"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.7.1 查询模块中的所有函数和类\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['AbsTransform',\n",
       " 'AffineTransform',\n",
       " 'Bernoulli',\n",
       " 'Beta',\n",
       " 'Binomial',\n",
       " 'CatTransform',\n",
       " 'Categorical',\n",
       " 'Cauchy',\n",
       " 'Chi2',\n",
       " 'ComposeTransform',\n",
       " 'ContinuousBernoulli',\n",
       " 'CorrCholeskyTransform',\n",
       " 'CumulativeDistributionTransform',\n",
       " 'Dirichlet',\n",
       " 'Distribution',\n",
       " 'ExpTransform',\n",
       " 'Exponential',\n",
       " 'ExponentialFamily',\n",
       " 'FisherSnedecor',\n",
       " 'Gamma',\n",
       " 'Geometric',\n",
       " 'Gumbel',\n",
       " 'HalfCauchy',\n",
       " 'HalfNormal',\n",
       " 'Independent',\n",
       " 'IndependentTransform',\n",
       " 'Kumaraswamy',\n",
       " 'LKJCholesky',\n",
       " 'Laplace',\n",
       " 'LogNormal',\n",
       " 'LogisticNormal',\n",
       " 'LowRankMultivariateNormal',\n",
       " 'LowerCholeskyTransform',\n",
       " 'MixtureSameFamily',\n",
       " 'Multinomial',\n",
       " 'MultivariateNormal',\n",
       " 'NegativeBinomial',\n",
       " 'Normal',\n",
       " 'OneHotCategorical',\n",
       " 'OneHotCategoricalStraightThrough',\n",
       " 'Pareto',\n",
       " 'Poisson',\n",
       " 'PowerTransform',\n",
       " 'RelaxedBernoulli',\n",
       " 'RelaxedOneHotCategorical',\n",
       " 'ReshapeTransform',\n",
       " 'SigmoidTransform',\n",
       " 'SoftmaxTransform',\n",
       " 'SoftplusTransform',\n",
       " 'StackTransform',\n",
       " 'StickBreakingTransform',\n",
       " 'StudentT',\n",
       " 'TanhTransform',\n",
       " 'Transform',\n",
       " 'TransformedDistribution',\n",
       " 'Uniform',\n",
       " 'VonMises',\n",
       " 'Weibull',\n",
       " 'Wishart',\n",
       " '__all__',\n",
       " '__builtins__',\n",
       " '__cached__',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__path__',\n",
       " '__spec__',\n",
       " 'bernoulli',\n",
       " 'beta',\n",
       " 'biject_to',\n",
       " 'binomial',\n",
       " 'categorical',\n",
       " 'cauchy',\n",
       " 'chi2',\n",
       " 'constraint_registry',\n",
       " 'constraints',\n",
       " 'continuous_bernoulli',\n",
       " 'dirichlet',\n",
       " 'distribution',\n",
       " 'exp_family',\n",
       " 'exponential',\n",
       " 'fishersnedecor',\n",
       " 'gamma',\n",
       " 'geometric',\n",
       " 'gumbel',\n",
       " 'half_cauchy',\n",
       " 'half_normal',\n",
       " 'identity_transform',\n",
       " 'independent',\n",
       " 'kl',\n",
       " 'kl_divergence',\n",
       " 'kumaraswamy',\n",
       " 'laplace',\n",
       " 'lkj_cholesky',\n",
       " 'log_normal',\n",
       " 'logistic_normal',\n",
       " 'lowrank_multivariate_normal',\n",
       " 'mixture_same_family',\n",
       " 'multinomial',\n",
       " 'multivariate_normal',\n",
       " 'negative_binomial',\n",
       " 'normal',\n",
       " 'one_hot_categorical',\n",
       " 'pareto',\n",
       " 'poisson',\n",
       " 'register_kl',\n",
       " 'relaxed_bernoulli',\n",
       " 'relaxed_categorical',\n",
       " 'studentT',\n",
       " 'transform_to',\n",
       " 'transformed_distribution',\n",
       " 'transforms',\n",
       " 'uniform',\n",
       " 'utils',\n",
       " 'von_mises',\n",
       " 'weibull',\n",
       " 'wishart']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "dir(torch.distributions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.7.2 查找特定函数和类的用法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function ones in module torch:\n",
      "\n",
      "ones(...)\n",
      "    ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor\n",
      "    \n",
      "    Returns a tensor filled with the scalar value `1`, with the shape defined\n",
      "    by the variable argument :attr:`size`.\n",
      "    \n",
      "    Args:\n",
      "        size (int...): a sequence of integers defining the shape of the output tensor.\n",
      "            Can be a variable number of arguments or a collection like a list or tuple.\n",
      "    \n",
      "    Keyword arguments:\n",
      "        out (Tensor, optional): the output tensor.\n",
      "        dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.\n",
      "            Default: if ``None``, uses a global default (see :func:`torch.set_default_tensor_type`).\n",
      "        layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.\n",
      "            Default: ``torch.strided``.\n",
      "        device (:class:`torch.device`, optional): the desired device of returned tensor.\n",
      "            Default: if ``None``, uses the current device for the default tensor type\n",
      "            (see :func:`torch.set_default_tensor_type`). :attr:`device` will be the CPU\n",
      "            for CPU tensor types and the current CUDA device for CUDA tensor types.\n",
      "        requires_grad (bool, optional): If autograd should record operations on the\n",
      "            returned tensor. Default: ``False``.\n",
      "    \n",
      "    Example::\n",
      "    \n",
      "        >>> torch.ones(2, 3)\n",
      "        tensor([[ 1.,  1.,  1.],\n",
      "                [ 1.,  1.,  1.]])\n",
      "    \n",
      "        >>> torch.ones(5)\n",
      "        tensor([ 1.,  1.,  1.,  1.,  1.])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(torch.ones)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([1., 1., 1., 1.])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.ones(4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "test",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
